package config

import (
	"context"
	"github.com/gogf/gf/v2/container/gvar"
	"github.com/gogf/gf/v2/os/gcfg"
)

type HyperNexusConfig struct {
	configFile string
	cfg        *gcfg.Config
}

func NewHyperNexusConfig(configFile string) HyperNexusConfig {
	h := HyperNexusConfig{
		configFile: configFile,
		cfg:        nil,
	}
	h.init()
	return h
}

func (h *HyperNexusConfig) init() {
	h.cfg, _ = gcfg.New()
	err := h.cfg.GetAdapter().(*gcfg.AdapterFile).SetPath("./config")
	if err != nil {
		panic("set config path error")
	}
	h.cfg.GetAdapter().(*gcfg.AdapterFile).SetFileName(h.configFile)
}

func (h *HyperNexusConfig) GetConfig() *gcfg.Config {
	return h.cfg
}

func (h *HyperNexusConfig) GetValue(ctx context.Context, key string, def ...interface{}) (*gvar.Var, error) {
	return h.cfg.Get(ctx, key, def...)
}

func (h *HyperNexusConfig) MustGetValue(ctx context.Context, key string, def ...interface{}) *gvar.Var {
	return h.cfg.MustGet(ctx, key, def...)
}
